home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / BAR3D.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  4.2 KB  |  137 lines

  1. {**********************************************}
  2. {   TBar3DSeries Component                     }
  3. {   Copyright (c) 1996-98 by David Berneda     }
  4. {      Series Developer Kit Example            }
  5. {**********************************************}
  6. {$I teedefs.inc}
  7. unit Bar3D;
  8.  
  9. { This Series component is derived from TBarSeries.
  10.   It has a new property:  OffsetValues
  11.  
  12.   This new property allows to specify a different ORIGIN value
  13.   for EACH bar point.
  14.   This can be used with standard TBarSeries components to
  15.   make a "Stacked-3D" chart type.
  16. }
  17. interface
  18.  
  19. uses
  20.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  21.   Forms, Dialogs, Teengine, Series;
  22.  
  23. type
  24.   TBar3DSeries = class(TBarSeries)
  25.   private
  26.     { Private declarations }
  27.     FOffsetValues:TChartValueList;
  28.   protected
  29.     { Protected declarations }
  30.     Procedure SetOffsetValues(Value:TChartValueList);
  31.   public
  32.     { Public declarations }
  33.     Constructor Create(AOwner: TComponent); override;
  34.     Function AddBar( Const AX,AY,AOffset:Double;
  35.                      Const AXLabel:String{$IFDEF D4}=''{$ENDIF};
  36.                      AColor:TColor{$IFDEF D4}=clTeeColor{$ENDIF}):Longint;
  37.     Procedure FillSampleValues(NumValues:Longint); override;
  38.     Function GetOriginValue(ValueIndex:Longint):Double; override;
  39.     Function MaxYValue:Double; override;
  40.     Function MinYValue:Double; override;
  41.     Function PointOrigin(ValueIndex:Longint; SumAll:Boolean):Double; override;
  42.   published
  43.     { Published declarations }
  44.     property OffsetValues:TChartValueList read FOffsetValues
  45.                                           write SetOffsetValues;
  46.   end;
  47.  
  48. implementation
  49.  
  50. Uses Chart,TeeProcs,TeCanvas,
  51.      TeeProco;  { <-- needed only for the "Samples" constant }
  52.  
  53. Constructor TBar3DSeries.Create(AOwner: TComponent);
  54. begin
  55.   inherited Create(AOwner);
  56.   FOffsetValues :=TChartValueList.Create(Self,TeeMsg_ValuesOffset); { <-- "offset" storage }
  57. end;
  58.  
  59. Procedure TBar3DSeries.SetOffsetValues(Value:TChartValueList);
  60. begin
  61.   SetChartValueList(FOffsetValues,Value); { standard method }
  62. end;
  63.  
  64. { calculate maximum Y value }
  65. Function TBar3DSeries.MaxYValue:Double;
  66. begin
  67.   result:=inherited MaxYValue;
  68.   if (MultiBar=mbNone) or (MultiBar=mbSide) then
  69.      result:=MaxDouble(result,FOffsetValues.MaxValue);
  70. end;
  71.  
  72. { calculate minimum Y value ( YValues and negative Offsets supported ) }
  73. Function TBar3DSeries.MinYValue:Double;
  74. var t:Longint;
  75. begin
  76.   result:=inherited MinYValue;
  77.   if (MultiBar=mbNone) or (MultiBar=mbSide) then
  78.      for t:=0 to Count-1 do
  79.          if FOffsetValues[t]<0 then result:=MinDouble(result,YValues[t]+FOffsetValues[t]);
  80. end;
  81.  
  82. Function TBar3DSeries.AddBar( Const AX,AY,AOffset:Double;
  83.                               Const AXLabel:String{$IFDEF D4}=''{$ENDIF};
  84.                               AColor:TColor{$IFDEF D4}=clTeeColor{$ENDIF}):Longint;
  85. begin
  86.   result:=AddXY(AX,AY,AXLabel,AColor); { standard add X,Y }
  87.   FOffsetValues.TempValue:=AOffset;
  88.   AddValue(result);
  89. end;
  90.  
  91. Procedure TBar3DSeries.FillSampleValues(NumValues:Longint);
  92. Var t:Longint;
  93.     tmpX,tmpY,StepX,MinY,DifY:Double;
  94. Begin
  95.   Clear;
  96.   CalcRandomBounds(NumValues,tmpX,StepX,tmpY,MinY,DifY);
  97.   for t:=1 to NumValues do { some sample values to see something in design mode }
  98.   Begin
  99.     tmpY:=Random(Round(DifY));
  100.     AddBar( tmpX,
  101.             10+Abs(tmpY),
  102.             Abs(DifY/(1+Random(5)))
  103.             {$IFNDEF D4},'',clTeeColor{$ENDIF});
  104.     tmpX:=tmpX+StepX;
  105.   end;
  106.   RefreshSeries;
  107. end;
  108.  
  109. { this overrides default bottom origin calculation }
  110. Function TBar3DSeries.PointOrigin(ValueIndex:Longint; SumAll:Boolean):Double;
  111. begin
  112.   result:=FOffsetValues.Value[ValueIndex];
  113. end;
  114.  
  115. { this makes this bar heigth to be: "offset" + "heigth" }
  116. Function TBar3DSeries.GetOriginValue(ValueIndex:Longint):Double;
  117. begin
  118.   result:=inherited GetOriginValue(ValueIndex)+FOffsetValues.Value[ValueIndex];
  119. end;
  120.  
  121. { Un-register the Series }
  122. Procedure TeeBar3DExitProc; far;
  123. begin
  124.   UnRegisterTeeSeries([TBar3DSeries]);
  125. end;
  126.  
  127. { Register the Series at Chart gallery }
  128. initialization
  129.   RegisterTeeSeries( TBar3DSeries, 'Bar3D', TeeMsg_GallerySamples, 1 );
  130. {$IFDEF D1}
  131.   AddExitProc(TeeBar3DExitProc);
  132. {$ELSE}
  133. finalization
  134.   TeeBar3DExitProc;
  135. {$ENDIF}
  136. end.
  137.